/*
 * Copyright (c) Huawei Device Co., Ltd. 2023. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <gtest/gtest.h>
#include <memory>

#include "ef_parser.h"
#include "mock_arf_manager.h"

namespace OHOS {
namespace SE {
namespace TEST {
using namespace testing;
using namespace testing::ext;
using namespace OHOS::SE;

class EfParserTest : public testing::Test {
public:
    static void SetUpTestCase() {};
    static void TearDownTestCase() {};
    void SetUp();
    void TearDown();
};

void EfParserTest::SetUp()
{
}

void EfParserTest::TearDown()
{
}

/**
 * @tc.name: ReadFileByPath_Test001
 * @tc.desc: Test ReadFileByPath.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByPath_Test001, TestSize.Level0)
{
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    ArfManager::GetInstance().SetUsedSeName(SE_NAME_SIM);
    std::vector<uint8_t> path = {0x01, 0x02, 0x03, 0x04};
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    uint16_t rspApdu = 0;
    efParser->ReadFileByPath(path, rspApdu);
    EXPECT_TRUE(rspApdu == 0x9000);
}

/**
 * @tc.name: ReadFileByPath_Test002
 * @tc.desc: Test ReadFileByPath.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByPath_Test002, TestSize.Level1)
{
    int offset = 0;
    int dataSize = -1;
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    ArfManager::GetInstance().SetUsedSeName(SE_NAME_SIM);
    std::vector<uint8_t> path = {0x01, 0x02, 0x03, 0x04};
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    uint16_t rspApdu = 0;
    efParser->ReadFileByPath(path, rspApdu);
    efParser->ReadFileByDataSize(offset, dataSize);
    EXPECT_TRUE(efParser != nullptr);
}

/**
 * @tc.name: ReadFileByPath_Test003
 * @tc.desc: Test ReadFileByPath.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByPath_Test003, TestSize.Level1)
{
    int offset = 0;
    int dataSize = 0;
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    ArfManager::GetInstance().SetUsedSeName(SE_NAME_SIM);
    std::vector<uint8_t> path = {0x01, 0x02, 0x03, 0x04};
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    uint16_t rspApdu = 0;
    efParser->ReadFileByPath(path, rspApdu);
    efParser->ReadFileByDataSize(offset, dataSize);
    EXPECT_TRUE(efParser != nullptr);
}

/**
 * @tc.name: ReadFileByPath_Test004
 * @tc.desc: Test ReadFileByPath.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByPath_Test004, TestSize.Level1)
{
    int offset = 0;
    int dataSize = 1;
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    ArfManager::GetInstance().SetUsedSeName(SE_NAME_SIM);
    std::vector<uint8_t> path = {0x01, 0x02, 0x03, 0x04};
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    uint16_t rspApdu = 0;
    efParser->ReadFileByPath(path, rspApdu);
    efParser->ReadFileByDataSize(offset, dataSize);
    EXPECT_TRUE(efParser != nullptr);
}

/**
 * @tc.name: ReadFileByPath_Test005
 * @tc.desc: Test ReadFileByPath.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByPath_Test005, TestSize.Level1)
{
    uint8_t record = 1;
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    ArfManager::GetInstance().SetUsedSeName(SE_NAME_SIM);
    std::vector<uint8_t> path = {0x01, 0x02, 0x03, 0x04};
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    uint16_t rspApdu = 0;
    efParser->ReadFileByPath(path, rspApdu);
    efParser->ReadFileRecord(record);
    EXPECT_TRUE(efParser != nullptr);
}
} // TEST
} // SE
} // OHOS